﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Widgets.Services;

namespace NGM.Portlets.Controllers {
    public class ToolbarController : Controller, IUpdateModel {
        private readonly IWidgetsService _widgetsService;

        public ToolbarController(IWidgetsService widgetsService) {
            _widgetsService = widgetsService;
        }

        public ActionResult Update(ToolbarViewModel viewModel, FormCollection formCollection, string returnUrl) {

            //if (viewModel.CreateLayer) {
            //    _widgetsService.CreateLayer("", "", "");
            //}

            if (!string.IsNullOrWhiteSpace(viewModel.ManageLayer)) {
                var layers = _widgetsService.GetLayers();
                
            }

            if (viewModel.EnableHiddenZones) {
                TempData["enablehiddenzones"] = viewModel.EnableHiddenZones;
            }

            return Redirect(returnUrl);
        }

        public RedirectResult EnableZone(string returnUrl, string zone) {
            return Redirect(returnUrl);
        }

        bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
            return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
        }

        void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
            ModelState.AddModelError(key, errorMessage.ToString());
        }
    }

    public class ToolbarViewModel {
        public bool CreateLayer { get; set; }
        public bool EnableHiddenZones { get; set; }
        public string ManageLayer { get; set; }
    }
}